package jp.co.ricoh.melody.presenters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.util.List;

import jp.co.ricoh.melody.R;
import jp.co.ricoh.melody.models.DayListModel;
import jp.co.ricoh.melody.models.IDay;
import jp.co.ricoh.melody.models.IDayListModel;
import jp.co.ricoh.melody.views.adapters.IDayListView;

/**
 * Copyright (C) 2016 RICOH Co.,LTD.
 * All rights reserved.
 * Set adapter for Day of Week.
 */

public class DayListPresenter extends BaseAdapter implements IDayListPresenter {


    private IDayListView mView;
    private final IDayListModel mModel = new DayListModel();


    public List<IDay> getDays() {
        return mModel.getDays();
    }

    @Override
    public void updateDay(int position, boolean logic) {
        mModel.updateDay(position, logic);
    }

    @Override
    public void updateAllDay(boolean[] logic) {
        mModel.updateAllDay(logic);
    }

    @Override
    public boolean[] getDaysRepeat() {
        return mModel.getDaysRepeat();
    }

    @Override
    public boolean selectedDay() {
        return mModel.selectedDay();
    }

    @Override
    public int getCount() {
        return mModel.getCount();
    }

    @Override
    public IDay getItem(int i) {
        return mModel.getItem(i);
    }

    @Override
    public long getItemId(int i) {
        return mModel.getID(i);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        IDay day = getItem(position);
        ItemViewHolder ivHolder;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mView.getViewContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.itemview, parent, false);
            ivHolder = new ItemViewHolder();
            ivHolder.iv = (ImageView) convertView.findViewById(R.id.dayTxt);

            convertView.setTag(ivHolder);
        } else {
            ivHolder = (ItemViewHolder) convertView.getTag();
        }
        ivHolder.iv.setBackgroundResource(day.getDrawble());
//        LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(R.dimen.dimen_size_day,R.dimen.dimen_size_day);
//        ivHolder.iv.setLayoutParams(parms);
        return convertView;
    }

    @Override
    public void onCreate(IDayListView view) {
        mView = view;
        mView.setListAdapter(this);
    }

    @Override
    public void onListUpdate() {
        notifyDataSetChanged();
    }

    @Override
    public void onItemClick(int i) {
        mModel.clickItem(i);
    }

    static class ItemViewHolder {
        ImageView iv;


    }
}
